package org.scala.test.t001

import scala.beans.BeanProperty

object SObj001 {
  
  val t1 = 3 ;
  
  @BeanProperty
  var name:String = "" ;
  
  
  println(t1);
  
  def sum(x:Int,y:Int) ={
    x+y
  }
  
  def sum(f:Int=>Int,a:Int,b:Int):Int={
    if(a>b) 0 else f(a)+sum(f,a+1,b)
  }
  def f(a:Int) = a*2 
  
  def sum4(f:Int=>Int):(Int,Int)=>Int={
    def sum5(a:Int,b:Int):Int=sum(f,a,b) ;
    sum5 
  }
  
  def coollection() ={
       println(t1);
     sum(1, 4) ;
      var a = 0;
      // for 循环
      for( a <- (1 to 10) ){
         println( "Value of a: " + a );
      }
      
      val t = List(1,2,3,5)
      var b =0 ;
      for(  b <- t){
        println(b );
      }
      
        a = 0;
      val numList = List(1,2,3,4,5,6,7,8,9,10);

      // for 循环
      for( a <- numList;if a != 3; if a < 8 ){
         println( "Value of a: " + a );
      }
      
      
      a = 0;
 
/*
      // for 循环
      var retVal = for{ a <- numList 
                        ; if a != 3; if a < 8
                      } yield a

      // 输出返回值
      for( a <- retVal){
         println( "Value of a: " + a );
      }
   }  */
    
  }
  
  def A(a:Int,b:Int,c:Int,d:Int):Int={
  
    a
  }
  def B(a:Int)(b:Int)(c:Int):Int={
    a
  }
  
  def sum6(f:Int=>Int)(a:Int,b:Int):Int={
    if(a>b) 0 else f(a) + sum6(f)(a+1,b)
  }
  
  def getType[T<:Integer](a:T){
    if(a == Int )
      println("Int") 
     
  }
  
  def  ++(i:Int):Int={
     var c = i 
     c +=1
     c 
  }
  
  
 
  def main(args:Array[String]):Unit={
    val t = coollection();
    println(t);
   /*  print("请输入菜鸟教程官网 : " )
      val line = Console.readLine
      
      println("谢谢，你输入的是: " + line)*/
    var l = List(1,2,3,4) 
    SObj001.++(1)
    
    
    var m = Map(1->"lihc",2->"yu");
    println(m);
    m += (1->"lihc2");
    println(m);
    m -= (1);
    println(m);
    val  f1 = factorial(30);
    println(f1);
    println(isUpper(null));
    
   // val f1 = f(3) ;
    val f11 = sum4(f) ;
    val f12 = f11.apply(1, 2) ;
    println("f12:"+f12) ;
    
    val f5 = sum6(f)(1,2)
    val f6 = sum6(f)_ 
    val f6result = f6(1,2)
    
  }
  
  def factorial(x:BigInt):BigInt={
    if(x==0) 1 else x*factorial(x-1) 
  }
  
  def isUpper(x:String):Boolean ={
    if(x == null) return false  
    val f = x.exists(_.isLower)  
    return f 
  }
}